package bean.dao;
import hbt.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class HibernateDAO {
	private static HibernateDAO instancia = null;
	private static SessionFactory sf = null;
	private Session session = null;
	
	public static HibernateDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateDAO();
		} 
		return instancia;
	}
	
	public Session getSession(){
		if(session == null || !session.isOpen())
			session = sf.openSession();
		return session;
	}
	
	public void closeSession(){
		if (session.isOpen()) session.close();
	}

}
